package org.example.system.model.vo;


import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.experimental.Accessors;


import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.Period;

/**
 * 车辆对象
 *
 * @author yinshijay
 */
@Schema(description = "车辆对象")
@Accessors(chain = true)
@Data
public class VehicleVO {
    private Integer id;
    // 车牌号
    private String plateNumber;

    // 车型
    private String model;


    // 车辆状态
    private String statusText;

    // 车辆图片路径
    private String carImagePath;

    //保单到期时间
    private LocalDate insuranceExpireDate;


    @Schema(description = "车辆ID")
    private Integer VehicleId;

    @Schema(description = "车辆品牌")
    private String brand;

    @Schema(description = "车牌号")
    private String licensePlate;

    @Schema(description = "保险单照片路径")
    private String insurancePath;

    @Schema(description = "保险到期日期")
    private LocalDate insuranceExpiry;

    @Schema(description = "车辆状态(0:空闲中 1:已预订 2:已出租 3:维修中 4：已报废)")
    private Integer status;

    @Schema(description = "车辆照片路径")
    private String photoPath;

    @Schema(description = "所在网点名称")
    private String locationTitle;

    @Schema(description = "所在网点地址")
    private String address;

    @Schema(description = "创建时间")
    private LocalDateTime createTime;

    @Schema(description = "更新时间")
    private LocalDateTime updateTime;

    @Schema(description = "车型id")
    private Integer modelId;

    @Schema(description = "车型名称")
    private String modelName;

    @Schema(description = "车型图片")
    private String modelPhoto;

    @Schema(description = "车型类型")
    private String modelType;

    @Schema(description = "车辆库存")
    private String stock;

    @Schema(description = "座位数")
    private Integer seatNumber;

    @Schema(description = "排量")
    private String displacement;

    @Schema(description = "排挡")
    private String gear;

    @Schema(description = "燃料类型")
    private String fuelType;

    @Schema(description = "燃油标号")
    private String fuelLabel;

    @Schema(description = "每日租金")
    private BigDecimal dailyRent;

    @Schema(description = "押金金额")
    private BigDecimal depositAmount;

    @Schema(description = "车型描述")
    private String remark;

    @Schema(description = "孩子")
    private String[] children;

    @Schema(description = "车龄")
    private Integer carAge;

    public void setCarAgeFromBuyTime(LocalDate buyTime) {
        if (buyTime != null) {
            Period period = Period.between(buyTime, LocalDate.now());
            int years = period.getYears();
            // 如果有部分年（即月份或天数），则加 1，否则保留原来的整年数
            this.carAge = (period.getMonths() > 0 || period.getDays() > 0) ? years + 1 : years;
        } else {
            this.carAge = 0; // 或者设为 0，依据需求
        }
    }
}
